import CCommonSearch from './index'
const reg = /^[\da-zA-Z]+$/

function codeOrName(filtersRaw, codeKey, nameKey) {
  if (!filtersRaw) {
    return
  }
  const name = filtersRaw.find(e => e.property === nameKey)
  if (name) {
    if (reg.test(name.value)) {
      name.id = codeKey
      name.property = codeKey
    } else {
      name.id = nameKey
      name.property = nameKey
    }
  }
}

export default {
  install(Vue) {
    Object.defineProperty(Vue.prototype, '$codeOrName', { value: codeOrName })
    const component = Vue.component.bind(Vue)
    // 省
    component('c-common-search-province', CCommonSearch({
      name: 'CCommonSearchProvince',
      props: {
        url: '/select-service/api/v1/administrativeDivisions/page',
        method: 'POST',
        valueKey: 'code',
        labelKey: 'name',
        queryKey: 'name',
        queryPosition: 'filtersRaw',
        columns: () => [
          {
            prop: 'code',
            label: '编码'
          },
          {
            prop: 'name',
            label: '名称'
          }
        ],
        filtersRaw: () => [
          { id: 'areaLevel', property: 'areaLevel', value: '2', operator: '=' }
        ]
      },
      syncProps: {
        id: {
          type: String,
          default: ''
        },
        cityLevel: {
          type: String,
          default: ''
        }
      }
    }))
    // 市、区、街道
    component('c-common-search-not-province', CCommonSearch({
      name: 'CCommonSearchNotProvince',
      props: {
        url: '/select-service/api/v1/administrativeDivisions/page',
        method: 'POST',
        valueKey: 'code',
        labelKey: 'name',
        queryKey: 'name',
        queryPosition: 'filtersRaw',
        columns: () => [
          {
            prop: 'code',
            label: '编码'
          },
          {
            prop: 'name',
            label: '名称'
          }
        ],
        parentId: {
          type: String,
          default: ''
        },
        parentCode: {
          type: String,
          default: ''
        },
        filtersRaw: function() {
          return [
            { id: 'areaLevel', property: 'areaLevel', value: '2', operator: '<>' }
          ]
        },
        beforeParams: function(paramsJson) {
          if (this.parentId) {
            paramsJson.filtersRaw.push({ id: 'parentId', property: 'parentId', value: this.parentId, operator: '=' })
          } else {
            paramsJson.filtersRaw.push({ id: 'parentCode', property: 'parentCode', value: this.parentCode, operator: '=' })
          }
          return paramsJson
        }
      },
      syncProps: {
        id: {
          type: String,
          default: ''
        },
        cityLevel: {
          type: String,
          default: ''
        }
      }
    }))
    // 办事处
    component('c-common-search-office', CCommonSearch({
      name: 'CCommonSearchOffice',
      props: {
        url: '/select-service/api/v1/organization/page',
        method: 'POST',
        valueKey: 'code',
        labelKey: 'name',
        formatLabel: function(v) {
          return `${v.name}(${v.code})`
        },
        queryPosition: 'filtersRaw',
        operator: 'LIKE',
        queryKey: 'name',
        columns: () => [
          {
            prop: 'code',
            label: '编码'
          },
          {
            prop: 'name',
            label: '名称'
          }
        ],
        filtersRaw: () => [
          { 'id': 'isOffice', 'property': 'isOffice', 'value': '1', 'operator': '=' },
          { 'id': 'status', 'property': 'status', 'value': '1', 'operator': '=' }
        ],
        beforeParams: function(paramsJson) {
          codeOrName(paramsJson.filtersRaw, 'code', 'name')
          return paramsJson
        }
      },
      syncProps: {
        officeTypeCode: {
          type: String,
          default: ''
        },
        officeTypeName: {
          type: String,
          default: ''
        },
        principalTel: {
          type: String,
          default: ''
        },
        principalCode: {
          type: String,
          default: ''
        },
        principalName: {
          type: String,
          default: ''
        }
      }
    }))
    // 域用户
    component('c-common-search-domain-user', CCommonSearch({
      name: 'CCommonSearchDomainUser',
      props: {
        url: '/slm-ctm/api/v1/ctmInvestmentManager/domainUser/page',
        method: 'POST',
        valueKey: 'account',
        labelKey: 'userName',
        formatLabel: function(v) {
          return `${v.userName}(${v.account})`
        },
        queryKey: 'userName',
        queryPosition: 'filtersRaw',
        operator: 'like',
        columns: () => [
          {
            prop: 'account',
            label: '账号'
          },
          {
            prop: 'userName',
            label: '姓名'
          },
          {
            prop: 'orgName',
            label: '组织'
          }
        ],
        filtersRaw: () => [
          { 'id': 'state', 'property': 'state', 'value': '1', 'operator': '=' }
        ],
        beforeParams: function(paramsJson) {
          paramsJson.filtersRaw.push({ 'id': 'userType', 'property': 'userType', 'value': '1', 'operator': '=' })
          codeOrName(paramsJson.filtersRaw, 'account', 'userName')
          return paramsJson
        }
      },
      syncProps: {
        phone: {
          type: String,
          default: ''
        },
        staffCode: {
          type: String,
          default: ''
        },
        id: {
          type: String,
          default: ''
        }
      }
    }))
    // mdm档案配置
    component('c-common-search-mdm', CCommonSearch({
      name: 'CCommonSearchMDM',
      props: {
        url: '/select-service/api/v1/custDocDef/page',
        method: 'POST',
        valueKey: 'code',
        labelKey: 'name',
        queryKey: 'name',
        queryPosition: 'filtersRaw',
        operator: 'like',
        columns: () => [
          {
            prop: 'code',
            label: '编码'
          },
          {
            prop: 'name',
            label: '名称'
          }
        ],
        custDocCode: {
          type: String,
          default: ''
        },
        excludes: {
          type: Array,
          default: () => []
        },
        beforeParams: {
          default: function(paramsJson) {
            paramsJson.filtersRaw.push({ id: 'custDocCode', property: 'custDocCode', value: this.custDocCode, operator: '=' })
            if (this.excludes.length > 0) {
              paramsJson.filtersRaw.push({ id: 'code', property: 'code', value: `[${this.excludes.join(',')}]`, operator: 'NOT IN' })
            }
            codeOrName(paramsJson.filtersRaw, 'code', 'name')
            return paramsJson
          }
        }
      },
      syncProps: {
        id: {
          type: String,
          default: ''
        }
      }
    }))
    // 未被引用的市场
    component('c-common-search-market-no-ref', CCommonSearch({
      name: 'CCommonSearchMarketNoRef',
      props: {
        url: '/slm-ctm/api/v1/ctmMarketTask/queryMinus',
        method: 'POST',
        valueKey: 'marketCode',
        labelKey: 'marketName',
        queryKey: 'marketName',
        queryPosition: 'filtersRaw',
        operator: 'like',
        columns: () => [
          {
            prop: 'marketCode',
            label: '编码'
          },
          {
            prop: 'marketName',
            label: '名称'
          }
        ],
        beforeParams: function(paramsJson) {
          codeOrName(paramsJson.filtersRaw, 'marketCode', 'marketName')
          // 通过权限控制
          // paramsJson.filtersRaw.push({ id: 'dataSource', property: 'dataSource', value: 'D', operator: '=' })
          return paramsJson
        }
      },
      syncProps: {
        provinceCode: {
          type: String,
          default: ''
        },
        provinceId: {
          type: String,
          default: ''
        },
        provinceName: {
          type: String,
          default: ''
        },
        cityId: {
          type: String,
          default: ''
        },
        cityCode: {
          type: String,
          default: ''
        },
        cityName: {
          type: String,
          default: ''
        },
        districtId: {
          type: String,
          default: ''
        },
        districtCode: {
          type: String,
          default: ''
        },
        districtName: {
          type: String,
          default: ''
        },
        streetId: {
          type: String,
          default: ''
        },
        streetCode: {
          type: String,
          default: ''
        },
        streetName: {
          type: String,
          default: ''
        },
        cityLevel: {
          type: String,
          default: ''
        },
        marketType: {
          type: String,
          default: ''
        },
        isOldMerchant: {
          type: [String, Number],
          default: ''
        }
      }
    }))
    // mdm国别
    component('c-common-search-mdm-country', CCommonSearch({
      name: 'CCommonSearchMDMCountry',
      props: {
        url: '/select-service/api/v1/country/page',
        method: 'POST',
        valueKey: 'code',
        labelKey: 'name',
        queryKey: 'name',
        queryPosition: 'filtersRaw',
        operator: 'like',
        placeholder: '请选择国别',
        columns: () => [
          {
            prop: 'code',
            label: '编码'
          },
          {
            prop: 'name',
            label: '名称'
          }
        ],
        beforeParams: function(paramsJson) {
          codeOrName(paramsJson.filtersRaw, 'code', 'name')
          return paramsJson
        }
      },
      syncProps: {
        id: {
          type: String,
          default: ''
        }
      }
    }))
    // 经销商
    component('c-common-search-dis', CCommonSearch({
      name: 'CCommonSearchDis',
      props: {
        url: '/select-service/api/v1/customer/page',
        method: 'POST',
        valueKey: 'code',
        labelKey: 'name',
        formatLabel: v => {
          return `${v.name}(${v.code})`
        },
        queryKey: 'name',
        queryPosition: 'filtersRaw',
        operator: 'like',
        placeholder: '请选择经销商',
        columns: () => [
          {
            prop: 'code',
            label: '编码'
          },
          {
            prop: 'name',
            label: '名称'
          }
        ],
        beforeParams: function(paramsJson) {
          codeOrName(paramsJson.filtersRaw, 'code', 'name')
          return paramsJson
        },
        syncAll: true
      },
      syncProps: {
        contactName: {
          type: String,
          default: ''
        },
        contactPhone: {
          type: String,
          default: ''
        },
        agencyCode: {
          type: String,
          default: ''
        },
        agencyName: {
          type: String,
          default: ''
        },
        businessAgencyCode: {
          type: String,
          default: ''
        },
        businessAgencyName: {
          type: String,
          default: ''
        },
        businessScope: {
          type: String,
          default: ''
        },
        businessStatus: {
          type: String,
          default: ''
        },
        businessTypeCode: {
          type: String,
          default: ''
        },
        businessTypeName: {
          type: String,
          default: ''
        },
        code: {
          type: String,
          default: ''
        },
        creationTime: {
          type: String,
          default: ''
        },
        cooperateStart: {
          type: String,
          default: ''
        },
        credentialNo: {
          type: String,
          default: ''
        },
        id: {
          type: String,
          default: ''
        },
        isElecBusiniess: {
          type: String,
          default: ''
        },
        name: {
          type: String,
          default: ''
        },
        oneCategoryCode: {
          type: String,
          default: ''
        },
        oneCategoryName: {
          type: String,
          default: ''
        },
        operateArea: {
          type: String,
          default: ''
        },
        parentCode: {
          type: String,
          default: ''
        },
        parentName: {
          type: String,
          default: ''
        },
        status: {
          type: String,
          default: ''
        },
        stopTime: {
          type: String,
          default: ''
        },
        twoCategoryCode: {
          type: String,
          default: ''
        },
        twoCategoryName: {
          type: String,
          default: ''
        }
      }
    }))

    // 门店建设项目号
    component('c-common-search-shop-build', CCommonSearch({
      name: 'CCommonSearchShopBuild',
      props: {
        url: '/slm-ctm/api/v1/shopConstruct/page',
        method: 'POST',
        valueKey: 'constCode',
        labelKey: 'constCode',
        queryKey: 'constCode',
        queryPosition: 'filtersRaw',
        operator: 'like',
        placeholder: '请选择门店建设项目号',
        title: '门店建设项目号',
        columns: () => [
          {
            prop: 'constCode',
            label: '编码'
          },
          {
            prop: 'constSchedule',
            label: '门店建设整体进度',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'BEFORE_CONST_SCHEDULE'
            }
          }
        ],
        filtersRaw: () => [
          { id: 'isEnd', property: 'isEnd', value: '0', operator: '=' }
        ]
      },
      syncProps: {
        constSchedule: {
          type: String,
          default: ''
        },
        constType: {
          type: String,
          default: ''
        },
        constState: {
          type: [String, Number],
          default: ''
        }
      }
    }))

    // 人员
    component('c-common-search-person', CCommonSearch({
      name: 'CCommonSearchPerson',
      props: {
        url: `${process.env.VUE_APP_BASE_API}/api/v1/user/queryAccountOrgPersonByParams`,
        method: 'POST',
        valueKey: 'adAccount',
        labelKey: 'personName',
        formatLabel: v => `${v.personName}(${v.adAccount})`,
        queryKey: 'personName',
        queryPosition: 'filtersRaw',
        operator: 'like',
        placeholder: '请选择人员',
        columns: () => [
          {
            prop: 'adAccount',
            label: '账号'
          },
          {
            prop: 'personName',
            label: '姓名'
          }
        ],
        syncAll: true,
        // 只查客户经理
        filtersRaw: () => [
          { id: 'isAccountManager', property: 'isAccountManager', value: '1', operator: '=' }
        ],
        // 通过办事处查
        byOffice: {
          type: Boolean,
          default: false
        },
        queryOfficeCode: {
          type: String,
          default: ''
        },
        // 通过客户查
        byCustomer: {
          type: Boolean,
          default: false
        },
        queryCustomerCode: {
          type: String,
          default: ''
        },
        // 是否包含当前登录账号
        containSelf: {
          type: Boolean,
          default: false
        },
        beforeParams: {
          default: function(paramsJson) {
            if (!paramsJson.filtersRaw) {
              paramsJson.filtersRaw = []
            }
            if (this.byOffice) {
              paramsJson.filtersRaw.push({ id: 'officeCode', property: 'officeCode', value: this.queryOfficeCode, operator: '=' })
            } else if (this.byCustomer) {
              paramsJson.filtersRaw.push({ id: 'customerCode', property: 'customerCode', value: this.queryCustomerCode, operator: '=' })
            }
            if (!this.containSelf) {
              paramsJson.filtersRaw.push({ id: 'adAccount', property: 'adAccount', value: this.$store.getters.currUser.account, operator: '<>' })
            }
            codeOrName(paramsJson.filtersRaw, 'adAccount', 'personName')
            return paramsJson
          }
        }
      }
    }))
    // 人员 新建档案
    component('c-common-search-person-by-office', CCommonSearch({
      name: 'CCommonSearchPersonNewArchive',
      props: {
        url: `${process.env.VUE_APP_BASE_API}/api/v1/user/personOrg/page`,
        method: 'POST',
        valueKey: 'adAccount',
        labelKey: 'personName',
        formatLabel: v => `${v.personName}(${v.adAccount})`,
        queryKey: 'personName',
        queryPosition: 'filtersRaw',
        operator: 'like',
        placeholder: '请选择人员',
        columns: () => [
          {
            prop: 'adAccount',
            label: '编码'
          },
          {
            prop: 'personName',
            label: '姓名'
          },
          {
            prop: 'mgrTypeName',
            label: '客户经理类型'
          }
        ],
        syncAll: true,
        queryOfficeCode: {
          type: String,
          default: ''
        },
        // 是否包含当前登录账号
        containSelf: {
          type: Boolean,
          default: false
        },
        beforeParams: {
          default: function(paramsJson) {
            if (!paramsJson.filtersRaw) {
              paramsJson.filtersRaw = []
            }
            if (this.queryOfficeCode) {
              paramsJson.filtersRaw.push({ id: 'orgCode', property: 'orgCode', value: this.queryOfficeCode, operator: '=' })
            }
            if (!this.containSelf) {
              paramsJson.filtersRaw.push({ id: 'adAccount', property: 'adAccount', value: this.$store.getters.currUser.account, operator: '<>' })
            }
            codeOrName(paramsJson.filtersRaw, 'adAccount', 'personName')
            return paramsJson
          }
        }
      }
    }))
    // 客户 档案新建 门店新建 里面的客户编码
    component('c-common-search-customer', CCommonSearch({
      name: 'CCommonSearchCustomer',
      props: {
        url: `${process.env.VUE_APP_BASE_API}/api/v1/ctmMdmCustomer/page`,
        method: 'POST',
        valueKey: 'code',
        labelKey: 'name',
        formatLabel: v => {
          return `${v.name}(${v.code})`
        },
        queryKey: 'name',
        queryPosition: 'filtersRaw',
        operator: 'like',
        placeholder: '请选择客户',
        filtersRaw: () => [
          { id: 'status', property: 'status', value: 1, operator: '=' }
        ],
        columns: () => [
          {
            prop: 'code',
            label: '编码'
          },
          {
            prop: 'name',
            label: '名称'
          }
        ],
        syncAll: true,
        officeCode: {
          type: String,
          default: ''
        },
        beforeParams: function(paramsJson) {
          if (this.officeCode) {
            paramsJson.filtersRaw.push({ id: 'agencyCode', property: 'agencyCode', value: this.officeCode, operator: '=' })
          }
          codeOrName(paramsJson.filtersRaw, 'code', 'name')
          return paramsJson
        },
        beforeRequest: function(axiosConfig) {
          axiosConfig.headers['Permission-PerCode'] = 'customer'
          axiosConfig.headers['Permission-App'] = 'slm'
          return axiosConfig
        }
      }
    }))
    // 根据账号获取客户经理
    component('c-common-search-by-account-customer-manager', CCommonSearch({
      name: 'CCommonSearchByAccountCustomerManager',
      props: {
        url: '/slm-ctm/api/v1/user/listCustomerManagerByAccounts',
        method: 'POST',
        valueKey: 'account',
        labelKey: 'name',
        queryKey: 'name',
        queryPosition: 'filtersRaw',
        operator: 'like',
        placeholder: '请选择',
        columns: () => [
          {
            prop: 'account',
            label: '账号'
          },
          {
            prop: 'name',
            label: '姓名'
          }
        ],
        beforeParams: {
          default: function(paramsJson) {
            paramsJson.filtersRaw.push({ id: 'accounts', property: 'accounts', value: this.$store.getters.currUser.account, operator: '=' })
            paramsJson.filtersRaw.push({ id: 'account', property: 'account', value: this.$store.getters.currUser.account, operator: '<>' })
            codeOrName(paramsJson.filtersRaw, 'account', 'name')
            return paramsJson
          }
        }
      },
      syncProps: {
        adAccount: {
          type: String,
          default: ''
        },
        agencyCode: {
          type: String,
          default: ''
        },
        agencyName: {
          type: [String, Number],
          default: ''
        },
        code: {
          type: [String],
          default: ''
        },
        mgrType: {
          type: [String],
          default: ''
        },
        sex: {
          type: [String],
          default: ''
        },
        soState: {
          type: [String],
          default: ''
        },
        tel: {
          type: [String],
          default: ''
        }
      }
    }))
    // 门店
    component('c-common-search-shop', CCommonSearch({
      name: 'CCommonSearchShop',
      props: {
        url: `${process.env.VUE_APP_BASE_API}/api/v1/ctmCustomerShopFiles/queryByCustomerCode/`,
        method: 'GET',
        valueKey: 'code',
        labelKey: 'name',
        queryKey: 'name',
        queryPosition: 'query',
        operator: 'like',
        placeholder: '请选择门店',
        remote: false,
        columns: () => [
          {
            prop: 'code',
            label: '编码'
          },
          {
            prop: 'name',
            label: '姓名'
          }
        ],
        syncAll: true,
        customerCode: {
          type: String,
          default: ''
        },
        beforeRequest: function(axiosConfig) {
          axiosConfig.url = `${process.env.VUE_APP_BASE_API}/api/v1/ctmCustomerShopFiles/queryByCustomerCode/${this.customerCode}`
          return axiosConfig
        }
      }
    }))
    // 地址
    component('c-common-search-addr', CCommonSearch({
      name: 'CCommonSearchAddr',
      props: {
        url: `${process.env.VUE_APP_BASE_API}/api/v1/ctmCustomerAddress/queryByCustomerCode/`,
        method: 'GET',
        valueKey: 'code',
        labelKey: 'name',
        queryKey: 'name',
        queryPosition: 'query',
        operator: 'like',
        placeholder: '请选择地址',
        remote: false,
        columns: () => [
          {
            prop: 'code',
            label: '编码'
          },
          {
            prop: 'name',
            label: '姓名'
          }
        ],
        syncAll: true,
        customerCode: {
          type: String,
          default: ''
        },
        beforeRequest: function(axiosConfig) {
          axiosConfig.url = `${process.env.VUE_APP_BASE_API}/api/v1/ctmCustomerAddress/queryByCustomerCode/${this.customerCode}`
          return axiosConfig
        }
      }
    }))
    // 门店通过客户
    component('c-common-search-shop-by-customer', CCommonSearch({
      name: 'CCommonSearchShopByCustomer',
      props: {
        url: `${process.env.VUE_APP_BASE_API}/api/v1/ctmCustomerShopBusiness/queryByCustomerCode/`,
        method: 'GET',
        valueKey: 'code',
        labelKey: 'name',
        queryKey: 'name',
        queryPosition: 'query',
        operator: 'like',
        placeholder: '请选择门店',
        remote: false,
        columns: () => [
          {
            prop: 'code',
            label: '编码'
          },
          {
            prop: 'name',
            label: '名称'
          }
        ],
        syncAll: true,
        customerCode: {
          type: String,
          default: ''
        },
        beforeRequest: function(axiosConfig) {
          axiosConfig.url = `${process.env.VUE_APP_BASE_API}/api/v1/ctmCustomerShopBusiness/queryByCustomerCode/${this.customerCode}`
          return axiosConfig
        }
      }
    }))
    // 业务账号
    component('c-common-search-account-by-customer', CCommonSearch({
      name: 'CCommonSearchAccountByCustomer',
      props: {
        url: `${process.env.VUE_APP_BASE_API}/api/v1/ctmCustomerAccountTo/queryByCustomerCode/`,
        method: 'GET',
        valueKey: 'accountCode',
        labelKey: 'accountName',
        queryKey: 'accountName',
        queryPosition: 'query',
        operator: 'like',
        placeholder: '请选择账号',
        remote: false,
        columns: () => [
          {
            prop: 'accountCode',
            label: '编码'
          },
          {
            prop: 'accountName',
            label: '名称'
          }
        ],
        syncAll: true,
        customerCode: {
          type: String,
          default: ''
        },
        exclude: [],
        beforeRequest: function(axiosConfig) {
          axiosConfig.url = `${process.env.VUE_APP_BASE_API}/api/v1/ctmCustomerAccountTo/queryByCustomerCode/${this.customerCode}`
          return axiosConfig
        },
        beforeParams: function(paramsJson) {
          if (!paramsJson.filtersRaw) {
            paramsJson.filtersRaw = []
          }
          if (this.exclude && this.exclude.filter(e => e !== undefined && e !== '').length > 0) {
            paramsJson.filtersRaw.push({ id: 'accountCode', property: 'accountCode', value: `[${this.exclude.join(',')}]`, operator: 'NOT IN' })
          }
          codeOrName(paramsJson.filtersRaw, 'accountCode', 'accountName')
          return paramsJson
        }
      }
    }))
    // 业务账号
    component('c-common-search-account', CCommonSearch({
      name: 'CCommonSearchAccount',
      props: {
        url: `/select-service/api/v1/account/page`,
        method: 'POST',
        valueKey: 'code',
        labelKey: 'name',
        queryKey: 'name',
        queryPosition: 'query',
        operator: 'like',
        placeholder: '请选择账号',
        columns: () => [
          {
            prop: 'code',
            label: '编码'
          },
          {
            prop: 'name',
            label: '名称'
          }
        ],
        syncAll: true,
        customerCode: {
          type: String,
          default: ''
        },
        beforeParams: function(paramsJson) {
          if (this.customerCode) {
            paramsJson.filtersRaw.push({ id: 'customerCode', property: 'customerCode', value: this.customerCode, operator: '=' })
          }
          return paramsJson
        },
        beforeRequest: function(axiosConfig) {
          return axiosConfig
        }
      }
    }))
    // 办事处查业务账号
    component('c-common-search-account-by-office', CCommonSearch({
      name: 'CCommonSearchAccountByOffice',
      props: {
        url: `/select-service/api/v1/account/page`,
        method: 'POST',
        valueKey: 'code',
        labelKey: 'name',
        queryKey: 'name',
        queryPosition: 'filtersRaw',
        operator: 'like',
        placeholder: '请选择账号',
        columns: () => [
          {
            prop: 'code',
            label: '编码'
          },
          {
            prop: 'name',
            label: '名称'
          }
        ],
        syncAll: true,
        officeCode: {
          type: String,
          default: ''
        },
        includeDisable: { // 是否包含停用
          type: Boolean,
          default: false
        },
        exclude: {
          type: Array,
          default: () => []
        },
        beforeParams: function(paramsJson) {
          if (!paramsJson.filtersRaw) {
            paramsJson.filtersRaw = []
          }
          paramsJson.filtersRaw.push({ id: 'agencyCode', property: 'agencyCode', value: this.officeCode, operator: '=' })
          if (!this.includeDisable) {
            paramsJson.filtersRaw.push({ id: 'status', property: 'status', value: 1, operator: '=' })
          }
          if (this.exclude && this.exclude.filter(e => e !== undefined && e !== '').length > 0) {
            paramsJson.filtersRaw.push({ id: 'code', property: 'code', value: `[${this.exclude.join(',')}]`, operator: 'NOT IN' })
          }
          codeOrName(paramsJson.filtersRaw, 'code', 'name')
          return paramsJson
        }
      }
    }))
    // 根据业务账号查门店
    component('c-common-search-shop-by-account', CCommonSearch({
      name: 'CCommonSearchShopByAccount',
      props: {
        url: `/api/v1/ctmCustomerShopBusiness/queryByAccountCode/`,
        method: 'GET',
        valueKey: 'code',
        labelKey: 'name',
        queryKey: 'name',
        queryPosition: 'query',
        operator: 'like',
        placeholder: '请选择门店',
        remote: false,
        columns: () => [
          {
            prop: 'code',
            label: '编码'
          },
          {
            prop: 'name',
            label: '名称'
          }
        ],
        syncAll: true,
        account: {
          type: String,
          default: ''
        },
        beforeRequest: function(axiosConfig) {
          axiosConfig.url = `${process.env.VUE_APP_BASE_API}/api/v1/ctmCustomerShopBusiness/queryByAccountCode/${this.account}`
          return axiosConfig
        }
      }
    }))
    // qup用户 行管
    component('c-common-search-qup-person', CCommonSearch({
      name: 'CCommonSearchQupPerson',
      props: {
        url: `${process.env.VUE_APP_BASE_API}/api/v1/user/domainUser/page`,
        method: 'POST',
        valueKey: 'account',
        labelKey: 'userName',
        formatLabel: v => `${v.userName}(${v.account})`,
        queryKey: 'userName',
        queryPosition: 'filtersRaw',
        operator: 'like',
        placeholder: '请选择人员',
        columns: () => [
          {
            prop: 'account',
            label: '账号'
          },
          {
            prop: 'userName',
            label: '姓名'
          }
        ],
        syncAll: true,
        userType: {
          type: String,
          default: '1'
        },
        // 只查客户经理
        filtersRaw: () => [
          { id: 'state', property: 'state', value: 1, operator: '=' },
          { id: 'userType', property: 'userType', value: this.userType, operator: '=' }
        ],
        beforeParams: {
          default: function(paramsJson) {
            if (!paramsJson.filtersRaw) {
              paramsJson.filtersRaw = []
            }
            codeOrName(paramsJson.filtersRaw, 'account', 'userName')
            return paramsJson
          }
        }
      }
    }))
    /**
     * 经销商合作终止中分页查询
     */
    component('c-common-search-customer-cooperation-end', CCommonSearch({
      name: 'CCommonSearchCustomerCooperationEnd',
      props: {
        url: `${process.env.VUE_APP_BASE_API}/api/v1/ctmMdmCustomer/pageOfCooperationEnd`,
        method: 'POST',
        valueKey: 'customerCode',
        labelKey: 'customerName',
        formatLabel: v => {
          return `${v.customerName}(${v.customerCode})`
        },
        queryKey: 'customerName',
        queryPosition: 'filtersRaw',
        operator: 'like',
        placeholder: '请选择客户',
        filtersRaw: () => [],
        columns: () => [
          {
            prop: 'customerCode',
            label: '编码'
          },
          {
            prop: 'customerName',
            label: '名称'
          }
        ],
        syncAll: true,
        officeCode: {
          type: String,
          default: ''
        },
        beforeParams: function(paramsJson) {
          if (this.officeCode) {
            paramsJson.filtersRaw.push({ id: 'officeCode', property: 'officeCode', value: this.officeCode, operator: '=' })
          }
          codeOrName(paramsJson.filtersRaw, 'customerCode', 'customerName')
          return paramsJson
        },
        beforeRequest: function(axiosConfig) {
          // axiosConfig.headers['Permission-PerCode'] = 'customer'
          // axiosConfig.headers['Permission-App'] = 'slm'
          return axiosConfig
        }
      }
    }))
  }
}
